import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/entity/lottery/lottery_list_bean.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../components/app_conifg.dart';
import '../../../entity/lottery/lotter_result_bean.dart';
import '../../../routes/routes.dart';
import '../../../utils/AppData.dart';
import '../../../utils/Tools.dart';

class LotteryResultDialogWidget extends StatefulWidget {
  final LotterResultBean? lotteryResultBean;
  final Function? onPress;

  LotteryResultDialogWidget(
      {super.key, required this.lotteryResultBean, this.onPress});

  @override
  _LotteryResultDialogWidgetState createState() =>
      _LotteryResultDialogWidgetState();
}

class _LotteryResultDialogWidgetState extends State<LotteryResultDialogWidget>
    with TickerProviderStateMixin {
  TabController? tabCtrLottery;
  bool isAll = true;

  @override
  void initState() {
    super.initState();
    tabCtrLottery = TabController(length: 2, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(Get.context!).size.width,
      height: 400,
      decoration: BoxDecoration(
        // color: Tools.fromHex('#FFE8CE'), // 背景颜色
        borderRadius: BorderRadius.circular(8), // 设置圆角
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Stack(
            // alignment: Alignment.center,
            children: [
              Image.asset("assets/images/ic_lottery_result_bg.png"),
              Container(
                width: MediaQuery.of(Get.context!).size.width,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    SizedBox(
                      height: 120,
                    ),
                    Text(
                      '恭喜您中奖啦!',
                      style: TextStyle(
                          color: Tools.fromHex('#F83F2D'), fontSize: 20),
                    ),
                    SizedBox(
                      height: 25,
                    ),
                    Container(
                      width: 160,
                      height: 60,
                      child: Row(
                        children: [
                          BaseImage(
                            url: widget.lotteryResultBean?.image ?? "",
                            width: 50,
                            height: 50,
                          ),
                          Expanded(
                              child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '${widget.lotteryResultBean?.name ?? "123"}',
                                style: TextStyle(
                                    fontWeight: FontWeight.w300,
                                    fontSize: 16,
                                    color: Tools.fromHex('#666666')),
                              ),
                              // Container(
                              //   alignment: Alignment.topRight,
                              //   child: Text(
                              //     'x${widget.lotteryResultBean?.prizeCount??0}',
                              //     style: TextStyle(
                              //         fontWeight: FontWeight.w300,
                              //         fontSize: 16,
                              //         color: Tools.fromHex('#666666')),
                              //   ),
                              // )
                            ],
                          )),
                        ],
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
          SizedBox(
            height: 10,
          ),
          GestureDetector(
            onTap: () {
              Navigator.pop(context);
              var data = LotteryListBean.fromJson(widget.lotteryResultBean?.prizeList);
              if(data.my?[0].type == 2) {
                Map<String, dynamic> params = {};
                params['type'] = 0;
                params['client'] =
                GetPlatform.isIOS ? AppConfig.clientIos : AppConfig
                    .clientAndroid;
                params['goodsList'] = getPlaceOrderGoodsList();
                params['sid'] = AppData.sid;
                params['isRaffleGoods'] = 1;
                Get.toNamed(Routes.fillOrder, arguments: params);
              }else{
                Tools.showToast('领取成功');
              }
            },
            child: Card(
              color: Colors.transparent,
              shadowColor: Colors.transparent,
              child: Container(
                width: 120,
                height: 40,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: Tools.fromHex('#F83F2D'), // 背景颜色
                  borderRadius: BorderRadius.circular(20), // 设置圆角
                ),
                padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
                child: Text(
                  '立即领取',
                  style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.w500,
                      fontSize: 16),
                ),
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          GestureDetector(
            onTap: () {
              Navigator.pop(context);
            },
            child: Image.asset(
              "assets/images/close.png",
              color: Colors.white,
            ),
          )
        ],
      ),
    );
  }

  ///下单商品列表
  List<Map<String, dynamic>> getPlaceOrderGoodsList() {
    List<Map<String, dynamic>> arr = [];
    Map<String, dynamic> info = {};
    info['buyNum'] = 1;
    var data = LotteryListBean.fromJson(widget.lotteryResultBean?.prizeList);
    info['goodsId'] = data.my?[0].typeValue;
    info['isSelect'] = 1;
    info['isSend'] = 0;
    info['specNum'] = 1;
    arr.add(info);
    return arr;
  }
}
